<%@ page import="com.google.gson.JsonArray"%>
<%@page import="com.entity.ContactNote"%>
<%@page import="com.entity.Contact"%>
<%@page import="com.entity.Message"%>
<%@page import="com.entity.IdealComment"%>
<%@page import="com.entity.Ideal"%>
<%@page import="com.service.FileService"%>
<%@page import="com.service.FileTypeService"%>
<%@page import="com.entity.File"%>
<%@page import="com.entity.FileType"%>
<%@page import="com.util.Time"%>
<%@page import="com.util.Content"%>
<%@page import="com.entity.Document"%>
<%@page import="com.service.EmployeeService"%>
<%@page import="com.entity.Task"%>
<%@page import="com.entity.Goal"%>
<%@page import="com.entity.Project"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
    <title>项目</title>
    
	<style type="text/css">
		.p{
			margin-left:auto;
			margin-right:auto;
			font-size:35px;
			color:blue;
			margin-bottom:30px;
		}
		
		.m{
			font-size:20px;
			margin:15px;
		}
		
		.f{
			float:left;
		}
		
		.r{
			float:right;
		}
		
		.clear{
			clear:both;
		}
	</style>
	<script type="text/javascript" charset="utf-8" src="editor/kindeditor.js"></script>
  </head>
  
  <body>
  	
  	<%
  		Project project=(Project)session.getAttribute("project");
  		
  		List<Goal> goals=(List<Goal>)session.getAttribute("goals");
  		List<Task> tasks=(List<Task>)session.getAttribute("tasks");
  		List<Document> documents=(List<Document>)session.getAttribute("documents");
  		List<FileType> fileTypes=(List<FileType>)session.getAttribute("fileTypes");
  		List<File> files=(List<File>)session.getAttribute("files");
  		List<Ideal> ideals=(List<Ideal>)session.getAttribute("ideals");
  		List<IdealComment> comments=(List<IdealComment>)session.getAttribute("comments");
  		List<Message> messages=(List<Message>)session.getAttribute("messages");
  		List<Contact> contacts=(List<Contact>)session.getAttribute("contacts");
  		List<ContactNote> contactNotes=(List<ContactNote>)session.getAttribute("contactNotes");
  		
  		EmployeeService employeeService=new EmployeeService();
  		FileTypeService fileTypeService=new FileTypeService();
  		FileService fileservice=new FileService();
  		
  		String m=(String)request.getAttribute("mm");
  		String t=(String)request.getAttribute("tt");
  	 %>
  
  	<div style="margin-top:30px;margin-bottom:10px">
		<div class="p " style="width:750px"><%=project.getName()%></div>
	</div>
  	
  	<div class="container" style="width:750px">
   	<div class="tabbable tabs-left container" style="width:750px">
        <ul class="nav nav-tabs ">
          <li id="main" class="active"><a data-toggle="tab" href="#lA" class="m">首页</a></li>
          <li id="aim" class=""><a data-toggle="tab" href="#lB" class="m">目标</a></li>
          <li id="document" class=""><a data-toggle="tab" href="#lC" class="m">资料库</a></li>
		  <li id="file" class=""><a data-toggle="tab" href="#lD" class="m">文件共享</a></li>
		  <li id="contact" class=""><a data-toggle="tab" href="#lE" class="m">联系人</a></li>
		  <li id="ideal" class=""><a data-toggle="tab" href="#lF" class="m">想法</a></li>
        </ul>
		
		
        <div class="tab-content " style="margin-top:2px;width:600px">
        
          <!-- 信息流 -->
          <div id="lA" class="tab-pane active ">
			<span style="color:#ff7400;font-size:32px;margin-bottom:20px">发布信息</span>
			<div class="controls">
              <textarea rows="6" style="width:500px;margin-left:40px;margin-top:20px" id="textarea" class="input-xlarge"></textarea>
            </div>
			
			<button class="btn btn-primary btn-large" style="margin-left:468px" id="post">发布</button>
			<br />
			<hr />
			
			<ul style="color:#ff7400;font-size:22px;margin-bottom:0px;border-radius: 3px 3px 0 0;margin-top:20px;width:500px;margin-left:24px" class="breadcrumb">
				<li class="active">
					<i class="icon-th"></i>信息流
				</li>
			</ul>
			
			<div class="well" style="width:500px;margin-left:20px">
				<ul style="padding-left:20px;list-style-type:none" id="ul">
					<%
						int len=messages.size()>5?5:messages.size();
						for(int i=0;i<len;i++){
						
					 %>
						<li style="padding-top:10px" >
							<img style="width:32px;height:32px" src="<%=employeeService.getById(messages.get(i).getEmployeeid()).getPic()%>"/>
							<span style="font-size:16px"><%=Content.shorten(messages.get(i).getContent(),40) %></span>
							<br/>
							<small style="font-size:12px" class="pull-left">——<%=Time.ago(messages.get(i).getCreatetime()) %>发布</small>
							<br/>
						</li>
					<%
						}
					 %>
				</ul>
				<div class="pagination pull-right" style="margin-top:35px">
					  <ul>
						<li><a onclick="page('start')" href="javascript:;">首页</a></li>
						<li><a onclick="page('previous')" href="javascript:;">上一页</a></li>
						<li><a onclick="page('next')" href="javascript:;">下一页</a></li>
						<li><a onclick="page('end')" href="javascript:;">尾页</a></li>
					  </ul>
				</div>
			</div>
          </div>
          
          <!-- 目标 -->
          <div id="lB" class="tab-pane ">
          	<div style="margin-bottom:20px">
          		<span style="color:#ff7400;width:200px;font-size:30px"><a href="creategoal.jspx" class="btn btn-primary">新建目标</a></span>
          		
          	</div>
          	
          	<%
          		for(Goal goal:goals){
          			int allProgress=0;
	          		int i=0;
	          		for(Task task:tasks){
	          			if(task.getGoalid().equals(goal.getId())){
	          				allProgress+=task.getRate();
	          				i++;
	          			}
	          		}
	          		if(i==0){
	          			allProgress=0;
	          		}else{
	          			allProgress=(allProgress/i);
	          		}
          			
          	 %>
          	
            <div class="well">
				<span style="width:150px" class="f"><h2><a onclick="setgoalid('<%=goal.getId() %>')" data-toggle="tab" href="#<%=goal.getId()%>"><%=goal.getName() %></a></h2></span>
				<div class="progress progress-info progress-striped f" style="width:200px;margin-top:10px">
			        <div style="width: <%=allProgress%>%;" class="bar">当前目标已完成<%=allProgress %>%</div>
			     </div>
			     <a class="btn btn-info r" href="editgoal.jspx?id=<%=goal.getId() %>" style=""> 编辑</a>
			     <div class="clear"></div>
				<div>
					<%=goal.getDesc() %>
				</div>
			</div>
			<%
				}
			 %>
			
		
          </div>
          
          <!-- 资料库-->
          <div id="lC" class="tab-pane">
            <div class="">
				<ul style="margin-bottom:0px;border-radius: 3px 3px 0 0;margin-top:-5px" class="breadcrumb">
					<li class="active">
						<a href=""><i class="icon-folder-open"></i>资料</a>
					</li>
					<li class="pull-right"><i class="icon-plus"></i><a class="link-black" href="createdocument.jspx">分享新资料</a></li>
				</ul>
				
				<%
					for(Document d:documents){
				 %>
				
				<div style="margin-top:13px;" class="wall">
					<blockquote>
					  <h4><a data-toggle="tab" href="#<%=d.getId()%>"><%=Content.shorten(d.getTitle(), 20) %></a></h4>
					  <p style="font-size:14px;line-height:1.5;"><%=Content.shorten(d.getContent())%></p>
					  <small class="pull-right"><%=employeeService.getById(d.getEmployeeid()).getUsername() %>发布于<%=Time.ago(d.getCreatetime()) %></small>
					  <a title="编辑" onclick="editdocument('<%=d.getId()%>')" href="javascript:;"><i class="icon-pencil"></i></a>
					  <a title="删除" onclick="deletedocument('<%=d.getId()%>')" href="javascript:;"><i class="icon-trash"></i></a>
					</blockquote>
				</div>
				
				<%
					}
				 %>
			</div>
          </div>
          
          <!-- 文件共享-->
          <div id="lD" class="tab-pane ">
            	<div class="">
			
					<ul style="margin-bottom:0px;border-radius: 3px 3px 0 0;margin-top:-5px" class="breadcrumb">
						<li class="active">
							<a data-toggle="tab" href="#lD"><i class="icon-th"></i>文件列表</a>
						</li>
						<li class="pull-right"><i class="icon-plus"></i><a class="link-black" href="createfolder.jspx">创建文件夹</a></li>
					</ul>
					<div class="wall">
						<table class="table table-striped">
							<thead>
								<tr>
									<th width="20px"></th>
									<th width="40%">名称</th>
									<th width="20%">文件数量</th>
									<th width="20%">文件夹大小</th>
									<th>创建人</th>
								</tr>
							</thead>
							<tbody>
								<%
									for(FileType fileType:fileTypes){
								 %>
								<tr>
									<td>
										<i class="icon-folder-open"></i>
									</td>
									<td><a data-toggle="tab" href="#<%=fileType.getId()%>"><%=fileType.getName() %></a></td>
									<td style="padding-left:30px"><%=fileservice.getNum(fileType.getId()) %></td>
									<td style="padding-left:20px"><%=Content.cal(fileservice.getSizeById(fileType.getId())+"")%></td>
									<td style="padding-left:18px"><%=employeeService.getById(fileType.getEmployeeid()).getUsername() %></td>
								</tr>
								<%
									}
								 %>
								
							</tbody>
						</table>
					</div>
			
			</div>
          </div>
          
          <!-- 联系人 -->
          <div id="lE" class="tab-pane ">
          
          	<div class="">
				<ul style="margin-bottom:20px;border-radius: 3px 3px 0 0" class="breadcrumb">
					<li class="active">
						<a href=""><i class="icon-user"></i>联系人</a>
					</li>
				</ul>
				<div class="wall">
					<div class="row">
						<div class="span3" style="height:500px">
							<a class="btn span2" href="createcontact.jspx"><i class="icon-plus"></i>添加联系人</a>
							<div class="clear"></div>
							<ul style="margin-top:15px;margin-left:20px" class="unstyled" id="cs">
								<%
									for(Contact contact:contacts){
										
								 %>
								 	<li style="line-height:30px">
										<i class="icon-list-alt"></i><a onclick="inf(this)" ref="<%=contact.getId() %>" href="javascript:;"><%=contact.getName() %></a>
									</li>
								 <%
								 	}
								  %>
								
							</ul>
						</div>
						<div id="inf" style="min-height:400px;border-left:1px solid #ccc;padding-left:15px" class="">
							
						</div>
					</div>
				</div>
			</div>
          	
          </div>
          
          <!-- 想法-->
          <div id="lF" class="tab-pane">
          	
          	<div class="">
				<ul style="margin-bottom:0px;border-radius: 3px 3px 0 0;margin-top:-5px" class="breadcrumb">
					<li class="active">
						<a data-toggle="tab" href="#1D"><i class="icon-fire"></i>想法</a>
					</li>
					<li class="pull-right"><i class="icon-plus"></i><a class="link-black" href="createideal.jspx">发表想法</a></li>
				</ul>
				<div style="margin-top:20px;margin-left:10px" class="wall">
					
					<%
						for(Ideal ideal:ideals){
					 %>
							<blockquote>

							  <h4><a data-toggle="tab" href="#<%=ideal.getId()%>"><%=Content.shorten(ideal.getTitle(), 20) %></a></h4>
							  <p style="font-size:14px;line-height:1.5;"><%=Content.shorten(ideal.getContent(), 60) %></p>

							  <small class="pull-right"><%=employeeService.getById(ideal.getEmployeeid()).getUsername()%>发表于<%=Time.ago(ideal.getCreatetime()) %></small>
							  <a title="编辑" onclick="editideal('<%=ideal.getId()%>')" href="javascript:;"><i class="icon-pencil"></i></a>
							  <a title="删除" onclick="deleteideal('<%=ideal.getId() %>')" href="javascript:;"><i class="icon-trash"></i></a>
							</blockquote>
					<%
						}
					 %>
					
				</div>
			</div>
          	
          </div>
          
          <!-- 具体联系人 -->
          <%
          	for(Contact contact:contacts){
          		
           %>
	         <div id="<%=contact.getId() %>" class=" tab-pane">
				
				<ul style="margin-bottom:20px;border-radius: 3px 3px 0 0" class="breadcrumb">
					<li class="active">
						<a href=""><i class="icon-user"></i>联系人</a>
					</li>
				</ul>
				<div class="wall" style="margin-left:30px">
						
					<address>
						<h3><%=contact.getName() %></h3>
						<p><%=contact.getCompanyName() %></p>
						<small>手机</small> <%=contact.getMobile() %><br>
						<small>固话</small><%=contact.getTel() %><br><br>
						<small>邮箱</small> <%=contact.getEmail() %><br>
						<small>地址</small> <%=contact.getAddress() %><br><br>
						<small>主页</small> <a href="<%=contact.getWebsite() %>"><%=contact.getWebsite() %></a><br>
						<small>微博</small> <a href="<%=contact.getWeibo() %>"><%=contact.getWeibo() %></a><br>
					</address>
					<div class="line">记录</div>
					<form>
						<textarea  rows="1" class="span5 sizechange"></textarea>
						<br>
						<a href="javascript:;" class="btn btn-primary" ref="<%=contact.getId() %>" onclick="addrecord(this)">发布</a>
					</form>
					
					<%
						for(ContactNote note:contactNotes){
							if(note.getContactid().equals(contact.getId())){
					 %>
						<blockquote>
						 <%=note.getContent() %>
						  <small><%=employeeService.getById(note.getEmployeeid()).getUsername() %>发布于<%=Time.ago(note.getCreatetime()) %></small>
						</blockquote>
					<%
							}
						}
					 %>
					
					<a data-toggle="tab" onclick="refreshcontactnote('<%=contact.getId() %>')" href="#lE">←返回联系人列表</a>
				</div>
				
			</div>
		 <%
			}
		 %>
          
          <!-- 具体想法 -->
          <%
          	for(Ideal ideal:ideals){
           %>
	          <div id="<%=ideal.getId()%>" class=" tab-pane">
				<ul style="margin-bottom:0px;border-radius: 3px 3px 0 0;margin-top:-5px" class="breadcrumb">
					<li class="active">
						<a data-toggle="tab" href="#1F"><i class="icon-fire"></i>想法</a>&gt;<%=Content.shorten(ideal.getTitle(), 6) %>
					</li>
					
				</ul>
				<div class="wall">
					  <div class="page-header">
						<h3><%=ideal.getTitle() %>&nbsp;&nbsp;<small><%=employeeService.getById(ideal.getEmployeeid()).getUsername()%>发表于<%=Time.ago(ideal.getCreatetime()) %></small></h3>
					  </div>
					  <p><%=ideal.getContent() %></p>
					  
					  <div class="line" style="margin-top:10px;margin-bottom:10px">
						<span style="font-size:20px">评论</span>
					  </div>
					  <form action="" method="post">
						<textarea rows="2" id="ideal"+<%=ideal.getId() %> class="span8 size" class="neirong" name="comment"></textarea>
						<br>
						<button class="btn" type="button" onclick="fabu(this)" ref="<%=ideal.getId() %>">发布</button>
					  </form>
					 
					 <%
					 	for(IdealComment comment:comments){
					 		if(comment.getIdealid().equals(ideal.getId())){
					  %>
						 <blockquote>
							 <%=comment.getContent() %>
							  <small>
								<%=employeeService.getById(comment.getEmployeeid()).getUsername()%>发表于<%=Time.ago(comment.getCreatetime()) %>
							    <a title="删除" onclick="del(this)" r="<%=comment.getIdealid()%>" ref="<%=comment.getId() %>" href="javascript:;"><i class="icon-trash"></i></a>
							  </small>
						 </blockquote>
					  <%
					  		}
						}
					  %>
					
					<a data-toggle="tab" href="#lF">←返回想法列表</a>
				</div>
			 </div>
          <%
          	}
          %>
          
          
          <!-- 具体文件 -->
          <%
			   for(FileType fileType:fileTypes){
		   %>
		   		<div id="<%=fileType.getId() %>" class=" tab-pane" style="margin-top:-10px">
			
						<a style="float:right" class="btn btn-primary" href="up.jspx?id=<%=fileType.getId()%>"><i class="icon-white  icon-share"></i>上传文件</a>
						<div class="clear"></div>
						
						<ul style="margin-bottom:0px;border-radius: 3px 3px 0 0;margin-top:15px" class="breadcrumb">
							<li class="active">
								<i class="icon-th"></i><a data-toggle="tab" href="#lD">文件共享</a>&gt;<a href=""><%=fileType.getName() %></a>
							</li>
							<li style="float:right"><a title="删除该文件夹" class="link-black" onclick="deletefolder('<%=fileType.getId()%>')" href="javascript:;"><i class="icon-trash"></i></a></li>
						</ul>
						<div class="wall">
							<table class="table table-striped">
								<thead>
									<tr>
										<th width="30px"></th>
										<th width="50%">名称</th>
										<th width="20%">大小</th>
										<th>创建人</th>
										<th></th>
									</tr>
								</thead>
								<tbody>
									
									<%
										for(File file:files){
											if(file.getFileTypeid().equals(fileType.getId())){
									 %>
											<tr>
												<td>
													<i class="icon-file"></i>
												</td>
												<td><a href="download.jspx?id=<%=file.getId()%>"><%=file.getName() %></a></td>
												<td><%=Content.cal(file.getFilesize()) %></td>
												<td><%=employeeService.getById(file.getEmployeeid()).getUsername() %></td>
												<td>
													<a title="删除该文件" class="link-black" onclick="deletefile('<%=file.getId()%>')" href="javascript:;"><i class="icon-trash"></i></a>
												</td>
											</tr>
									<%
											}
										}
									 %>
									
								</tbody>
							</table>
							
							<a data-toggle="tab" href="#lD">←返回</a>
						</div>
				</div>
		   <%
				}
		    %>
          
          
          <!-- 具体资料 -->
          <%
			for(Document d:documents){
		  %>
		  	<div id="<%=d.getId() %>" class="tab-pane">
	          	<div class="">
					<ul style="margin-bottom:0px;border-radius: 3px 3px 0 0;margin-top:-5px" class="breadcrumb">
						<li class="active">
							<a data-toggle="tab" href="#lC"><i class="icon-folder-open"></i>资料</a>&gt;<%=Content.shorten(d.getTitle(), 20) %>
						</li>
					</ul>
					<div class="wall">
						  <div class="page-header">
							<h3><%=d.getTitle() %>&nbsp;&nbsp;<small><%=employeeService.getById(d.getEmployeeid()).getUsername() %>发布于 <%=Time.ago(d.getCreatetime()) %></small></h3>
						  </div>
						  <p><%=d.getContent() %></p>
						  <a data-toggle="tab" href="#lC">←返回资料列表</a>
					</div>
				</div>
          	</div>
		  <%
		  	}
		   %>
		   
		   
          <!-- 具体任务 -->
          <%
          	for(Goal goal:goals){
          		int allProgress=0;
          		int i=0;
          		for(Task task:tasks){
          			if(task.getGoalid().equals(goal.getId())){
          				allProgress+=task.getRate();
          				i++;
          			}
          		}
          		if(i==0){
          			allProgress=0;
          		}else{
          			allProgress=(allProgress/i);
          		}
          		
           %>
           
          <div id="<%=goal.getId() %>" class="tab-pane">
          	
          	<div class="well">
				<span style="width:150px" class="f"><h2><a data-toggle="tab" ><%=goal.getName() %></a></h2></span>
				<div class="progress progress-info progress-striped f" style="width:500px;margin-top:10px;color:black;">
			        <div style="width: <%=allProgress%>%;" class="bar">当前目标已完成<%=allProgress %>%</div>
			     </div>
			     
			     <div class="clear"></div>
				<div>
					<%=goal.getDesc() %>
				</div>
			</div>
			
			<a class="btn btn-success" href="createtask.jspx?id=<%=goal.getId() %>"><i class="icon-plus icon-white"></i>添加新任务</a>
			
			<hr>
			
			<dl>
			
				<%
					for(Task task:tasks){
						if(task.getGoalid().equals(goal.getId())){
						Employee e=employeeService.getById(task.getEmployeeid());
				 %>
			
	       			<dt><i class="icon-bookmark"></i>
		       			<a href="edittask.jspx?id=<%=task.getId()%>" ><%=task.getName() %></a>
		       			&nbsp;&nbsp;&nbsp;<%=e.getUsername() %>
	       			</dt>
	       			<dd><%=task.getDesc() %></dd>
	       			<div class="progress">
					  <div style="width:<%=task.getRate()%>%;" class="bar"><%=task.getRate() %>%</div>
					</div>
      		
	      		<%
          				}
	      			}
	      		 %>
	      		 
			</dl>
			
          </div>
          <%
          	}
           %>
          
       
      	</div>
      
      </div>
      </div>

         
	<script type="text/javascript">
		
		//textarea点击变大，失去焦点变小	
		document.onclick=c;
		function c(){
			var s=$(".sizechange");
			s.focusin(function(){
				s.attr("rows","3");
			});
			s.focusout(function(){
				s.attr("rows","1");
			});
			
			
			var ss=$(".size");
			ss.focusin(function(){
				ss.attr("rows","5");
			});
			ss.focusout(function(){
				ss.attr("rows","2");
			});
		}
	
		//分页
		function page(type){
			if('start'==type){
				$.get("page.jspx",{type:type},function(gson){
					showmsg(gson);
				});
			}else if('previous'==type){
				$.get("page.jspx",{type:type},function(gson){
					showmsg(gson);
				});
			}else if('next'==type){
				$.get("page.jspx",{type:type},function(gson){
					showmsg(gson);
				});
			}else if('end'==type){
				$.get("page.jspx",{type:type},function(gson){
					showmsg(gson);
				});
			}
		}
		
		function showmsg(gson){
			$("#ul").children().remove();
			for(var i=0;i<gson.length;i++){
				var li=$("<li>").attr("style","padding-top:10px");
				var img=$("<img>").attr("style","width:32px;height:32px").attr("src",gson[i].employeeid);
				var span=$("<span>").attr("style","font-size:16px").text(gson[i].content);
				var small=$("<small>").attr("style","font-size:12px").attr("class","pull-left").text(gson[i].createtime);
				li.append(img).append(span).append($("<br>")).append(small).append($("<br>"));
				$("#ul").append(li);
			}
		}
		
		$(document).ready(function(){
			$("#post").click(function(){
				var content=$("#textarea").val();
				
				if(content!=""){
					$.get("message.jspx",{content:content},function(json){
						/* if($("#ul").children("li").length>0){
							$("#ul").children("li").eq(0).before($("<li>").append($("<img>").attr("style","width:32px;height:32px").attr("src",json.id)).append($("<span>").attr("style","font-size:16px").text(json.content)).append($("<br/>")).append($("<small>").attr("class","pull-left").attr("style","font-size:12px").text(json.createtime)).append($("<br/>")));
						}else{
							$("#ul").append($("<li>").append($("<img>").attr("style","width:32px;height:32px").attr("src",json.id)).append($("<span>").attr("style","font-size:16px").text(json.content)).append($("<br/>")).append($("<small>").attr("class","pull-left").attr("style","font-size:12px").text(json.createtime)).append($("<br/>")));
						} */
						page('start');
						$("#textarea").val("");
						
					});
				}
				
				
			});
		});
		
		function refreshcontactnote(id){
			var a=$("#cs").children("li");
			var c;
			for(var i=0;i<a.length;i++){
				if(a.eq(i).children("a").eq(0).attr("ref")==id){
					c=a.eq(i).children("a").eq(0);
				}
			}
			inf(c);
		}
		
		function setgoalid(id){
			$.get("setgoalid.jspx",{id:id});
		}
		
		var m="<%=m%>";
		//var ms=new Array();
		//var x=0;
		
		clear();
		if("main"==m){
			$("#main").attr("class","active");
			$("#lA").attr("class","tab-pane active");
		
		}else if("aim"==m){
			$("#aim").attr("class","active");
			$("#lB").attr("class","tab-pane active");
		}else if("document"==m){
			$("#document").attr("class","active");
			$("#lC").attr("class","tab-pane active");
		}else if("file"==m){
			$("#file").attr("class","active");
			$("#lD").attr("class","tab-pane active");
		}else if("contact"==m){
			$("#contact").attr("class","active");
			$("#lE").attr("class","tab-pane active");
		}else if("ideal"==m){
			$("#ideal").attr("class","active");
			$("#lF").attr("class","tab-pane active");
		}else if(m.length>10){
			var t="<%=t%>";
			if(t=="file"){
				$("#file").attr("class","active");
			}else if(t=="goal"){
				$("#aim").attr("class","active");
			}
			
			$("#"+m).attr("class","tab-pane active");
			/* ms[x]=m;
			x++; */
		}
		
		function clear(){
			$("#main").attr("class","");
			$("#lA").attr("class","tab-pane");
			$("#aim").attr("class","");
			$("#lB").attr("class","tab-pane");
			$("#document").attr("class","");
			$("#lC").attr("class","tab-pane");
			$("#file").attr("class","");
			$("#lD").attr("class","tab-pane");
			$("#contact").attr("class","");
			$("#lE").attr("class","tab-pane");
			$("#ideal").attr("class","");
			$("#lF").attr("class","tab-pane");
			/* for(var i=0;i<ms.length;i++){
				$("#"+ms[i]).attr("class","tab-pane");
			} */
		}
		
		function addrecord(obj){
			var btn=$(obj);
			var c=btn.parent().children("textarea").val();
			var id=btn.attr("ref");
			if(c!=""){
				$.get("addrecord.jspx",{id:id,c:c},function(json){
					btn.parent().children("textarea").val("");
					
					var blockquote=$("<blockquote>");
					blockquote.text(json.content);
					blockquote.append($("<small>").text(json.employeeid));
					blockquote.insertAfter(btn.parent());
				});
			}
			
		}
		
		function delcontact(obj){
			var r=confirm("确定删除吗");
			if(r==true){
				var id=$(obj).attr("ref");
				$.get("deletecontact.jspx",{id:id},function(json){
					$("#inf").text("");
					
					$("#cs").children().remove();
					for(var i=0;i<json.length;i++){
						var li=$("<li>").attr("style","line-height:30px");
						li.append($("<i>").attr("class","icon-list-alt")).append($("<a>").attr("href","javascript:;").attr("ref",json[i].id).attr("onclick","inf(this)").text(json[i].name));
						$("#cs").append(li);
					}
					
				});
			}
			
		}
		
		function note(obj){
			var id=$(obj).attr("ref");
			$.get("contactajax.jspx",{id:id,m:"dfg"},function(result){
				$("#inf").append($("<div>").attr("class","line").text("记录"));
				var len=result.length>3?3:result.length;
				for(var i=0;i<len;i++){
					$("#inf").append($("<blockquote>").text(result[i].content).append($("<small>").text(result[i].createtime)));
				}	
				
				$("#inf").append($("<a>").attr("data-toggle","tab").attr("href","#"+id).text("查看所有记录"));
				
				$("#inf").append($("<br>")).append($("<br>"));
				//编辑联系人
				$("#inf").append($("<a>").attr("href","editcontact.jspx?id="+id).attr("class","btn btn-primary").text("编辑").append($("<i>").attr("class","icon-pencil icon-white")));
				//删除联系人
				$("#inf").append($("<a>").attr("onclick","delcontact(this)").attr("ref",id).attr("href","javascript:;").attr("style","margin-left:10px").attr("class","btn btn-danger").text("删除").append($("<i>").attr("class","icon-trash icon-white")));		
				//$("#inf").show();
			});
		}
		
		function inf(obj){
			var id=$(obj).attr("ref");
			$.get("contactajax.jspx",{id:id,m:"inf"},function(result){
				var name = result.name;
				var companyname = result.companyName;
				var mobile = result.mobile;
				var tel = result.tel;
				var email = result.email;
				var address = result.address;
				var website = result.website;
				var weibo = result.weibo;
				
				$("#inf").text("");
				var a=$("<address>");
				
				a.append($("<h3>").text(name));
				a.append($("<p>").text(companyname));
				a.append($("<small>").text("手机:"));
				a.append($("<small>").text(mobile));
				a.append($("<br>"));
				
				a.append($("<small>").text("固话:"));
				a.append($("<small>").text(tel));
				a.append($("<br>"));
				a.append($("<br>"));
				
				a.append($("<small>").text("邮箱:"));
				a.append($("<small>").text(email));
				a.append($("<br>"));
				
				a.append($("<small>").text("地址:"));
				a.append($("<small>").text(address));
				a.append($("<br>"));
				a.append($("<br>"));
				
				a.append($("<small>").text("主页:"));
				a.append($("<small>").append($("<a>").attr("href",website).text(website)));
				a.append($("<br>"));
				
				a.append($("<small>").text("微博:"));
				a.append($("<small>").append($("<a>").attr("href",weibo).text(weibo)));
				a.append($("<br>"));
				a.append($("<br>"));
				
				$("#inf").append(a);
				
				note(obj);
			});
		}
	
		//cycle();
		
		function cycle(){
			var content=$("#ul").children("li").eq(0).children("span").eq(0).text().trim();
			
			$.get("messagecycle.jspx",{content:content},function(json){
				if(json!=null){
					if($("#ul").children("li").length>0){
			
						for(var i=0;i<json.length;i++){
							//$("#ul").children("li").eq(0).before($("<li>").attr("style","padding-top:10px").text(json[i].content));
							$("#ul").children("li").eq(0).before($("<li>").append($("<img>").attr("style","width:32px;height:32px").attr("src",json[i].id)).append($("<span>").attr("style","font-size:16px").text(json[i].content)).append($("<br/>")).append($("<small>").attr("class","pull-left").attr("style","font-size:12px").text(json[i].createtime)).append($("<br/>")));
						}
						
					}else{
						
						for(var i=0;i<json.length;i++){
							//$("#ul").append($("<li>").attr("style","padding-top:10px").text(json[i].content));
							$("#ul").append($("<li>").append($("<img>").attr("style","width:32px;height:32px").attr("src",json[i].id)).append($("<span>").attr("style","font-size:16px").text(json[i].content)).append($("<br/>")).append($("<small>").attr("class","pull-left").attr("style","font-size:12px").text(json[i].createtime)).append($("<br/>")));
						}
					}
				}
				
			});
			
			setTimeout("cycle()",20000);
		}
				
		function fabu(obj){
			var text=$(obj).parent().children().eq(0).val();
			var idealId=$(obj).attr("ref");
			
			if(text!=""){
				$.get("idealcomment.jspx",{text:text,idealId:idealId},function(json){
				$(obj).parent().parent().children().remove("blockquote");
				
				for(var i=json.length-1;i>=0;i--){
					var block=$("<blockquote>");
					block.append(json[i].content);
					block.append($("<small>").text(json[i].name+"发布于"+json[i].time).append($("<a>").attr("title","删除").attr("onclick","del(this)").attr("ref",json[i].commentid).attr("r",json[i].idealid).attr("href","javascript:;").append($("<li>").attr("class","icon-trash"))));
					
					$(obj).parent().after(block);
				}
				
				$(obj).parent().children().eq(0).val("");
				
				});
			}
			
		}
		
		function del(obj){
			var r=confirm("确定删除吗");
			if(r==true){
				 var commentid=$(obj).attr("ref");
				var idealid=$(obj).attr("r");
				var div=$(obj).parent().parent().parent();
				$.get("delidealcomment.jspx",{commentid:commentid,idealid:idealid},function(json){
					div.children().remove("blockquote");
					
					for(var i=0;i<json.length;i++){
						var block=$("<blockquote>");
						block.append(json[i].content);
						block.append($("<small>").text(json[i].name+"发布于"+json[i].time).append($("<a>").attr("title","删除").attr("onclick","del(this)").attr("ref",json[i].commentid).attr("r",json[i].idealid).attr("href","javascript:;").append($("<li>").attr("class","icon-trash"))));
						//block.appendTo($(obj).parent().parent());
						
						div.children("form").eq(0).after(block);
						
					}
				});
			}
		}
		
		function deletedocument(id){
			var r=confirm("确定删除吗");
			if(r==true){
				$.get("is.jspx",{id:id,type:"document"},function(result){
					if("ok"==result){
						window.location.href="deletedocument.jspx?id="+id; 
					}else{
						alert("该文档不是您创建，无法删除");
					}
				});
				 
			}
		}
		
		function editdocument(id){
			$.get("is.jspx",{id:id,type:"document"},function(result){
				if("ok"==result){
					window.location.href="editdocument.jspx?id="+id; 
				}else{
					alert("该文档不是您创建，无法编辑");
				}
			});
				 
		}
		
		function deletefolder(id){
			var r=confirm("确定删除吗");
			if(r==true){
				$.get("is.jspx",{id:id,type:"folder"},function(result){
						if("ok"==result){
							window.location.href="deletefolder.jspx?id="+id; 
						}else{
							alert("该文件夹不是您创建，无法删除");
						}
					});
			}
		}
		
		function deletefile(id){
			var r=confirm("确定删除吗");
			if(r==true){
				$.get("is.jspx",{id:id,type:"file"},function(result){
					if("ok"==result){
						window.location.href="deletefile.jspx?id="+id; 
					}else{
						alert("该文件不是您创建，无法删除");
					}
				});
			}
		}
		
		function deleteideal(id){
			var r=confirm("确定删除吗");
			if(r==true){
				$.get("is.jspx",{id:id,type:"ideal"},function(result){
					if("ok"==result){
						window.location.href="deleteideal.jspx?id="+id; 
					}else{
						alert("该想法不是您创建，无法删除");
					}
				});
			}
		}
		
		function editideal(id){
			$.get("is.jspx",{id:id,type:"ideal"},function(result){
				if("ok"==result){
					window.location.href="editideal.jspx?id="+id; 
				}else{
					alert("该想法不是您创建，无法编辑");
				}
			});
		}
		
	</script>
	
  </body>
</html>

